package com.xieke.admin.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 添加一个静态资源路径的映射，不会覆盖默认的资源路径，以当前文件中的配置为例
 * 映射完成后在项目中请求http://localhost:8080/image/xx.png就可以读取到所映射的绝对路径中的xx.png了
 * @Auther: halo
 * @Date: 2018/8/19 17:59
 * @Description:
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {
    @Value("${my.upload.imgPath}")
    private String path;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String staticMapping="/image/**";
        String localDirectory = "file:"+path;
        registry.addResourceHandler(staticMapping).addResourceLocations(localDirectory);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
